home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Developer Utilities / Installer 4.0.3 SDK / Script Examples / File Compare by Procedure / myCompareProc.r < prev    next >
Encoding:
Text File  |  1994-11-15  |  8.0 KB  |  215 lines  |  [TEXT/MPS ]

  1. //
  2. //    myCompareProc.r
  3. //
  4. //        This example installs a copy of the "ReadMe" file to the folder
  5. //        'Compare Proc Example:' at the root of the selected target volume.
  6. //        Since the same file will be being installed over itself on repeated
  7. //        installations, it will not be possible to see the effects of the
  8. //        file version comparison unless you modify the 'vers' (2) resource
  9. //        item of the installed file to a higher version, and then save the
  10. //        modified file to the same location. Then on the next installation
  11. //        a dialog will be displayed asking the user "Newer, Older, Cancel".
  12. //        Note that during Easy Install, a newer file will simply not
  13. //        be replaced, while under Custom Install a dialog with choices
  14. //        is presented to the user.
  15. //
  16. //        This example script uses a custom version compare procedure to
  17. //        check whether a target file about to be replaced is older, newer,
  18. //        or the same version as the file that is about to replace it.
  19. //
  20. //        A custom version procedure is a code resource, compiled from a
  21. //        seperate source file ( ours is written in C ). That code is linked
  22. //        to a file by declaring an 'invc' resource within the Installer
  23. //        script, that is then referenced from within a file atom ( 'infa' ). 
  24. //
  25. //        A custom version procedure simply returns the version number 
  26. //        of the target file based on whatever method the scriptwriter 
  27. //        feels is appropriate. A more appropriate name might have been
  28. //        custom Get Version procedure, since the version compare procedure 
  29. //        does not actually perform the comparison between files.
  30. //    
  31. //        The Installer will use that returned version number to perform
  32. //        it's usual version comparison. No further action is needed from
  33. //        the custom version compare procedure, once it has returned the
  34. //        version number of the file. 
  35. //
  36. //        The Installer will handle setting up the file for the custom version 
  37. //        compare procedure. There is no need to open the file or the file's 
  38. //        resource fork from within the version compare procedure. The resource
  39. //        items can be read immediately from within the custom version procedure.
  40. //    
  41. //        Our custom version procedure returns the version number found
  42. //        in the target file's 'vers' (1) resource. If no 'vers' (1)
  43. //        resource item is found in the target file, then the custom version
  44. //        proc will return the 'vers' (2) of the target file. If neither
  45. //        the 'vers' (1) or 'vers' (2) resource is found, then the custom
  46. //        version compare procedure returns 0.
  47. //    
  48. //        This, by the way, is what the Installer normally does anyway, so
  49. //        our custom version procedure isn't really all that valuable in it's
  50. //        present form. You may customize the source code for the provided
  51. //        custom version compare procedure to return the version number of a
  52. //        file as is appropriate for your project needs.
  53. //
  54. //        You must specify the flags 'useVersProcToCompare' for the custom
  55. //        version procedure to be called from within a file atom ( 'infa' ).
  56. //        You will most likely also want to set the flag 'leaveAloneIfNewer'
  57. //        within your file atom, so that a newer file will not be replaced
  58. //        when installing from Easy Install, and that a dialog asking the
  59. //        user to choose "newer, older, cancel" is provided to the user
  60. //        when a newer target file is encountered during a Custom Install.
  61. //
  62. //        IMPORTANT: You must either manaully set the source version number 
  63. //        within the file atom ( 'infa' ) or create a ScriptCheck extension that
  64. //        computes the value during ScriptChecking process.  See the 
  65. //        ScriptCheck User's Guide for more information on writing ScriptCheck
  66. //        extensions.
  67. //
  68. //        You must also create a resource of type 'invc' that specifies the
  69. //        resource type and resource ID of the code resource item containing
  70. //        the custom version procedure. These values are established within
  71. //        the compile ( C ) line of the makefile provided for creating the
  72. //        custom version compare procedure.
  73. //
  74. //
  75. //        mark young • 08/21/94
  76. //
  77. //        Copyright 1993-1994, Apple Computer, Inc., All Rights Reserved
  78. //
  79.  
  80. #include "InstallerTypes.r"
  81.  
  82. // include the file containing custom version compare procedure code resource item
  83. // - note that since this external file is in the form of a file containing
  84. // already compiled resources, that the include line does not use '#include' 
  85. // and that it is terminated with a semicolon.
  86. include "GetFileVersion";
  87.  
  88. resource 'inpk' (100) {
  89.     format0 {
  90.         showsOnCustom,
  91.         removable,
  92.         dontForceRestart,
  93.         0,
  94.         0,
  95.         "ReadMe to “Compare Proc Example” folder.",
  96.         {    
  97.         'infa', 1000    // file atom using the version compare procedure
  98.         },
  99.     }
  100. };
  101.  
  102. resource 'infa' (1000) {
  103.     format1 {
  104.         deleteWhenRemoving,
  105.         deleteWhenInstalling,
  106.         copy,                            
  107.         dontIgnoreLockedFile,
  108.         dontSetFileLocked,
  109.         useVersProcToCompare,            //  • Use creation date for compare
  110.         srcNeedNotExist,
  111.         rsrcForkInRsrcFork,
  112.         leaveAloneIfNewer,                //  • Do not update a newer file
  113.         updateExisting,                    
  114.         copyIfNewOrUpdate,
  115.         rsrcFork,
  116.         dataFork,
  117.         0,
  118.         0x0,
  119.         10000,                            // target file spec
  120.         {    
  121.             20000,                         // source file spec
  122.             0, 
  123.             0    
  124.         },
  125.         
  126.         0x07108000,            //  • The source version number in BCD format 
  127.                             //    This version number will be used by the version
  128.                             //     proc specified below to determine whether or not
  129.                             //  existing target file, if any, should be replaced.
  130.                             
  131.                             // HINT FOR CREATING THIS VALUE - if you'd like an
  132.                             // easy way to determine this hex value, in ResEdit 
  133.                             // open any file with a version visible from GetInfo .
  134.                             // Double click to open a 'vers' resource and note 
  135.                             // the version displayed. Then open the same 'vers'
  136.                             // resource with the ResEdit menu item
  137.                             // "Resource/Open using Hex editor" ( you must have
  138.                             // a resource item selected ). The first eight digits
  139.                             // in the center column are the binary coded decimal
  140.                             // form of the 'vers' resource item.
  141.                             
  142.                             
  143.         128,                //  • 'invc' rsrc ID for custom version proc
  144.                         
  145.         0,
  146.         "Read Me"
  147.         }
  148.     };
  149.  
  150. resource 'invc' ( 128 ) {
  151.     format0 {
  152.         'infn',                //  The resource type of the actual custom proc
  153.         128,                //  The resource id of the actual custom proc
  154.                             // NOTE: The code resource type and ID
  155.                             // values are specified within the makefile 
  156.                             // for the compare proc code resource. 
  157.                             // In this example the lines that create the 
  158.                             // compare proc code resource are in the same 
  159.                             // makefile as the one that builds the Installer 
  160.                             // script. You should use the values specified 
  161.                             // in the makefile to fill in these fields.
  162.         
  163.         0,                    //  The minimum amount of memory needed by the proc
  164.                             //    NOTE: A value of 0 specifies that the Installer's
  165.                             //     allocated memory will be used by the version
  166.                             //     compare code resource. Unless your code resource
  167.                             //     has a specific need for its own memory heap you
  168.                             //    should always assign this field a value of 0.
  169.                             
  170.         "Returns vers 2 version number.",
  171.         }
  172.     };
  173.  
  174. // target file spec for ReadMe file
  175. resource 'intf' (10000) {
  176.     format1 {
  177.         noSearchForFile,                 // use default search path
  178.         
  179.         TypeCrMustMatch,                 // If this is set to TypeCrMustMatch
  180.                                         // then a file with a different type
  181.                                         // and creator than those specified
  182.                                         // below will not be replaced.
  183.                                         // If this is set to TypeCrNeedNotMatch
  184.                                         // then type and creator of an existing
  185.                                         // target file are ignored.
  186.         
  187.         // The Type and Creator fields will be used to set the
  188.         // file's Type and Creator when a new file is created. 
  189.         'ttro',                         // TYPE for new file
  190.         'ttxt',                         // CREATOR for new file
  191.         
  192.         0,                                 // finder attribute flags
  193.                                         // filled by ScriptCheck is value is 0
  194.         
  195.         1,                                  // creation date for new file
  196.         1,                                  // modification date for new file
  197.                                         // NOTE: DATE values are filled
  198.                                         // by ScriptCheck if the value is 1
  199.                                             
  200.         0,                                 // search proc ID ( 'insp' ), none used
  201.         
  202.         ":Compare Proc Example:Read Me"    // path to target file
  203.         }
  204.     };
  205.  
  206. // source file spec for Read Me file
  207. resource 'infs' (20000) {
  208.     'ttro',
  209.     'ttxt',
  210.     0x1,
  211.     noSearchForFile,
  212.     TypeCrMustMatch,
  213.     "Disk1:Read Me"                        // path to source file
  214.     };
  215.